home *** CD-ROM | disk | FTP | other *** search
- Path: in2.uu.net!peach!atl1!mikec
- From: mikec@atl1.america.net (Michael J. Callahan)
- Newsgroups: comp.lang.c++
- Subject: Re: Aborting Constructors, Part II
- Date: 3 Feb 1996 08:28:37 -0500
- Organization: Access America(TM), P.O. Box 1222, Alpharetta, GA 30239-1222
- Message-ID: <mikec.823353055@atl1>
- References: <4eoeck$t6n@news.ios.com> <4eq99t$fpu@fsuj01.rz.uni-jena.de> <marnoldDM529E.3CH@netcom.com>
- NNTP-Posting-Host: atl1.america.net
- X-Newsreader: NN version 6.5.0 #3 (NOV)
-
- >>Problem 2: The language already provides an automatic call to delete
- >>if you throw an exception from an object that was allocated using new.
- >>The code above would cause delete to be called twice! Once again, heap
- >>corruption is likely.
- >>
-
- Now how did I miss that? Through my reading I try to keep abreast of
- stds, as they evolve, but I profess ignorance of the above point. Could
- you elaborate on this a little more?
-
- It sounds as if you are saying that the raw memory allocated for the
- ctor to be run against is automatically freed by virtue of an exception
- being thrown within a ctor. Of course this seems to mean that exceptions
- have to treat their invocation differently from within ctors, as versus
- other placement positions in code, which implies more knowledge than I
- thought an exception had. It also seems to imply that once you have thrown
- an exception in a ctor, that object no longer exists (if indeed the raw
- memory for the object has automatically and unconditionly been deallocated).
- I must confess I have never tried to test/access an object that threw an
- exception in its ctor to see whether the object was just an invalid instance
- or actually no longer existed.
-
- So under the covers, a new allocates raw memory for the object to occupy,
- and begins running the ctor on that raw memory. Within the ctor, if an
- exception is thrown, the raw memory allocation if deallocated, the instance
- in effect no longer exists?
-
- Is that recent behavior to the evolving std, or did I just miss it? If
- recent, is it implemented in many compilers yet?
-
- Anyone else???
- -------------------------------
- |\/|ike C. -- mikec@america.net
- *note: insert clever tagline here...
-
-
-
-